package control.member;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.member.MemberService;
import model.member.MemberVO;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class MemberController extends MultiActionController{
	private MemberService memberService;
	
	public MemberController(MemberService memberService) {
		super();
		this.memberService = memberService;
	}

	public MemberController() {
		super();
		// TODO Auto-generated constructor stub
	}


	public ModelAndView home(HttpServletRequest request, HttpServletResponse response) throws Exception{
		return new ModelAndView("home");
	}
	public ModelAndView loginPage(HttpServletRequest request, HttpServletResponse response) throws Exception{
		return new ModelAndView("login.member");
	}

	
	public ModelAndView login(HttpServletRequest request, HttpServletResponse response,HttpSession session,MemberVO vo) throws Exception{
		System.out.println(vo);
		MemberVO mvo=memberService.login(vo);
		System.out.println("controller mvo:"+mvo);
		if(mvo!=null){
			session.setAttribute("loginMember", mvo);
		}
			return new ModelAndView("JsonView","loginInfo",mvo);
	}	
	public ModelAndView mainLogin(HttpServletRequest request, HttpServletResponse response,HttpSession session,MemberVO vo) throws Exception{
		System.out.println(vo);
		MemberVO mvo=memberService.login(vo);
		System.out.println("controller mvo:"+mvo);
		if(mvo!=null){
			session.setAttribute("loginMember", mvo);
		}
			return new ModelAndView("home","loginInfo",mvo);
	}	
	public ModelAndView logout(HttpServletRequest request, HttpServletResponse response,HttpSession session,MemberVO vo) throws Exception{
	
		if(session!=null){
			session.invalidate();
		}
			return new ModelAndView("home");
	}	
	
	
}
